var tpl = require("./tpl/alert.htm");
$('body').append(tpl);

exports.setType = function (type) {
    type = type ? 'alert-' + type : 'alert-success';
    $('#top-alert').find(".alert-content").addClass(type);
    return this;
};
exports.setMsg = function (msg) {
    if (!msg) msg = '删除成功';
    $('#top-alert').find(".alert-content").html(msg);
    return this;
};
exports.show = function (msg, type) {
    this.setType(type);
    this.setMsg(msg);
    $('#top-alert').fadeIn().delay(2000).fadeOut();
    return this;
};
exports.appear = function (msg, type, callback) {
    this.setType(type);
    this.setMsg(msg);
    $('#top-alert').fadeIn().delay(2000).fadeOut();
    if (type != 'error')
        setTimeout(function () {
            window.history.go(-1)
        }, 2000);
    else if (typeof callback == "function")
        return callback();
    return this;
};